package priv.mill.ws;
import java.io.IOException;

import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.RemoteEndpoint.Basic;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

import org.apache.log4j.Logger;

@ServerEndpoint("/keServer")
public class MyWebSocket {
	private static final Logger logger = Logger.getLogger(
			MyWebSocket.class);
	
	@OnOpen
	public void onOpen(){
		System.out.println("has client login");
		
		
	}
	
	@OnMessage
	public void messageHandler(String mes,Session session) throws IOException, Throwable{
		Basic remote = session.getBasicRemote();
		remote.sendText("this is server info:"+mes);
		int temp=0;
		while (temp++<3) {
			Thread.currentThread().sleep(1000);
			remote.sendText(temp+"onserver");
		}
//		session.close();
	}
	
	@OnClose
	public void doClose() {
		System.out.println("goodby");
		
	}
}
